package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00103.TeenagerDay00103Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00103.TeenagerDay00103Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00104.PizzaDay00104Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00104.PizzaDay00104Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00104.PizzaDay00104Contion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00104.PizzaDay00104Model;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00104.PizzaDay00104Presenter;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay00104 extends BasterFragment implements OnRefreshLoadMoreListener, PizzaDay00104Contion.vier {


    public static SmartRefreshLayout PizzaSmartRefreshLayout;
    private RecyclerView PizzaRecyclerView;
    public PizzaDay00104Adpter adpter;
    public  PizzaDay00104Presenter pizzaDay00104Presenter;
    public int pizzanum=30;
    public int pizzabuju=0;
    public boolean ispizza = true;


    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day00104;
    }

    @Override
    public void initView() {

        PizzaSmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Pizza_SmartRefreshLayout);
        PizzaRecyclerView = (RecyclerView) findViewById(R.id.Pizza_RecyclerView);
        PizzaSmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        PizzaRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));

        pizzaDay00104Presenter = new PizzaDay00104Presenter(this,new PizzaDay00104Model());
        pizzaDay00104Presenter.teenager("/video/findVideos?currentPage="+pizzanum+"&pageSize=10");

    }

    @Override
    public void initDate() {

    }

    @Override
    public void getvier(List<PizzaDay00104Bean.DataBean> dataBeans) {

        for (PizzaDay00104Bean.DataBean dataBean : dataBeans) {
            dataBean.setPizzaLayout(++pizzabuju);
            if (pizzabuju==4){
                pizzabuju=0;
            }
        }
        PizzaSmartRefreshLayout.finishLoadMore();
        PizzaSmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new PizzaDay00104Adpter(dataBeans);
            PizzaRecyclerView.setAdapter(adpter);
        }else {
            if (ispizza){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        ispizza=false;
        pizzanum++;
        pizzaDay00104Presenter.teenager("/video/findVideos?currentPage="+pizzanum+"&pageSize=10");
        Log.i("BlankFragmentDay001","--04加载:"+pizzanum);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        if (ispizza){
            pizzanum=30;
        }
        pizzaDay00104Presenter.teenager("/video/findVideos?currentPage="+pizzanum+"&pageSize=10");
        Log.i("BlankFragmentDay001","--04刷新:"+pizzanum);

    }


}
